<template  >
  <div class="all">
    <!-- 页头 -->
    <el-container class="allContainer">
      <el-header class="head">
        <div class="divHead"></div>
        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <div>
                <div class="topFont">车辆缴费账单</div>
              </div>
            </div>
          </el-col>
          <!-- --------------------------------新增--------------------------- -->
          <!-- --------------------------------新增--------------------------- -->
          <div class="divBtn">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="carpayAdd = true"
              >新增</el-button
            >
            <el-dialog
              title="车辆缴费新增"
              :visible.sync="carpayAdd"
              @close="closeDialogAddgsVisible"
            >
              <div class="dialogAll">
                <div class="left">
                  <div class="rightFont">车辆账单信息：</div>
                  <div class="rightForm">
                    <div class="carpayForm">
                      <el-form ref="carpayForm" label-width="80px" size="mini">
                        <el-form-item
                          label="车牌号码"
                          :required="true"
                          style="width: 280px; padding-top: 20px"
                        >
                          <el-input
                            v-model="carpayForm.carNum"
                            @blur="queryCarNum"
                          ></el-input>
                        </el-form-item>
                        <el-form-item
                          label="车辆类型"
                          :required="true"
                          style="width: 280px"
                        >
                          <el-input v-model="carpayForm.carTypeName"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="车辆品牌"
                          :required="true"
                          style="width: 280px"
                        >
                          <el-input v-model="carpayForm.carBrand"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="车辆型号"
                          :required="true"
                          style="width: 280px"
                        >
                          <el-input v-model="carpayForm.carModel"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="开始时间"
                          :required="true"
                          style="width: 280px"
                        >
                          <el-input v-model="carpayForm.accessIn"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="结束时间"
                          :required="true"
                          style="width: 280px"
                        >
                          <el-input v-model="carpayForm.accessOut"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="缴费金额"
                          :required="true"
                          style="width: 260px"
                        >
                          <el-input
                            v-model="carpayForm.informationMoney"
                          ></el-input>
                        </el-form-item>
                      </el-form>
                    </div>
                  </div>
                </div>
                <div class="right">
                  <div class="leftFont">车主基本信息：</div>
                  <div class="leftForm">
                    <div class="carpayForm">
                      <el-form ref="carpayForm" label-width="80px" size="mini">
                        <el-form-item
                          label="车主姓名"
                          :required="true"
                          style="
                            width: 280px;
                            padding-top: 20px;
                            padding-left: 20px;
                          "
                        >
                          <el-input v-model="carpayForm.staffsName"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="联系方式"
                          :required="true"
                          style="width: 280px; padding-left: 20px"
                        >
                          <el-input v-model="carpayForm.staffsTel"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="人员性别"
                          :required="true"
                          style="width: 280px; padding-left: 20px"
                        >
                          <el-input v-model="carpayForm.staffsSex"></el-input>
                        </el-form-item>
                        <el-form-item
                          label="单位名称"
                          :required="true"
                          style="width: 280px; padding-left: 20px"
                        >
                          <el-input
                            v-model="carpayForm.enterpriseName"
                          ></el-input>
                        </el-form-item>
                        <el-form-item
                          label="所属楼宇"
                          :required="true"
                          style="width: 280px; padding-left: 20px"
                        >
                          <el-input
                            v-model="carpayForm.buildingName"
                          ></el-input>
                        </el-form-item>
                        <el-form-item
                          label="房间名称"
                          :required="true"
                          style="width: 280px; padding-left: 20px"
                        >
                          <el-input v-model="carpayForm.roomName"></el-input>
                        </el-form-item>
                        <el-form-item label="人脸照片" :required="true" style="width: 280px;padding-left: 20px">
                          <div style="width: 100px;height: 100px;" class="demo-basic--circle">
                            <div class="block">
                              <el-avatar shape="square" :size="100" :src="carpayForm.staffsPhoto">
                              </el-avatar>
                            </div>
                          </div>
                        </el-form-item>
                      </el-form>
                    </div>
                  </div>
                </div>
              </div>
              <div slot="footer" style="text-align: center">
                <el-button @click="carpayAdd = false">取 消</el-button>
                <el-button type="primary" @click="add">确 定</el-button>
              </div>
            </el-dialog>
            <el-popconfirm title="确定删除吗？" @confirm="delByIds">
              <el-button slot="reference" size="mini" type="warning" icon="el-icon-delete">批量删除
              </el-button>
            </el-popconfirm>
          </div>
        </el-row>
      </el-header>
      <el-main class="bottomMain">
        <div class="divMain">
          <template>
            <!-- 模糊查询 -->
            <div class="mainTop">
              <div class="divInputAll">
                <!-- 输入框 -->
                <div class="divInput">
                  <div class="inputFont">车辆号码：</div>
                  <div style="float: left">
                    <el-input
                      size="mini"
                      placeholder="请输入车辆号码"
                      v-model="queryCarpay.carNum"
                    >
                    </el-input>
                  </div>
                </div>
                <div class="divInput">
                  <div class="inputFont">联系方式：</div>
                  <div style="float: left">
                    <el-input
                      size="mini"
                      placeholder="请输入联系方式"
                      v-model="queryCarpay.staffsTel"
                    >
                    </el-input>
                  </div>
                </div>
                <div class="divSelect">
                  <div class="inputFont">车辆类型：</div>
                  <div style="float: left">
                    <el-select
                      size="mini"
                      v-model="queryCarpay.carTypeName"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in carTypes"
                        :key="item.carTypeId"
                        :label="item.carTypeName"
                        :value="item.carTypeName"
                      >
                      </el-option>
                    </el-select>
                  </div>
                </div>
                <!--------------------------------- 查询重置按钮---------------------- -->
                <div class="likeBtn">
                  <el-button
                    size="mini"
                    type="success"
                    icon="el-icon-search"
                    @click="loadCarpays"
                    >查询</el-button
                  >
                  <el-button size="mini" @click="allCarpays" plain
                    >重置</el-button
                  >
                </div>
              </div>
            </div>
          </template>
          <!---------------------------- 查所有 ------------------------------>
          <!---------------------------- 查所有 ------------------------------>
          <div class="divSelAll">
            <template>
              <el-table :data="carpayList" border style="width: 100%;font-size: xx-small;margin: auto;"
                @selection-change="handleSelectionChange" :row-style="{ height: '22px' }"
                :cell-style="{ padding: '1px' }">
                <el-table-column fixed type="selection" prop="carpayId" width="46">
                </el-table-column>
                <el-table-column
                  fixed
                  prop="staffsName"
                  label="车主姓名"
                  width="120"
                >
                </el-table-column>
                <el-table-column prop="staffsTel" label="联系方式" width="100">
                </el-table-column>
                <el-table-column prop="carNum" label="车牌号码" width="90">
                </el-table-column>
                <el-table-column prop="carModel" label="车辆型号" width="90">
                </el-table-column>
                <el-table-column prop="carTypeName" label="车辆类型" width="90">
                </el-table-column>
                <el-table-column
                  prop="informationMoney"
                  label="缴费金额"
                  width="100"
                >
                </el-table-column>
                <el-table-column
                  prop="carpayOuttime"
                  label="缴费时间"
                  width="220"
                >
                </el-table-column>

                <el-table-column label="操作" width="304">
                  <template slot-scope="scope">
                    <!-- --------------------------------详情--------------------------- -->
                    <!-- --------------------------------详情--------------------------- -->
                    <el-button @click="handleClick(scope.row.carpayId)" type="text" size="small">详情</el-button>
                    <el-dialog title="车辆缴费详情" :append-to-body="true" :visible.sync="carpayMesg"
                      @close="closeDialogAddgsVisible">
                      <div class="dialogAll">
                        <div class="left">
                          <div class="rightFont">车辆账单信息：</div>
                          <div class="rightForm">
                            <div class="carpayForm">
                              <el-form
                                ref="carpayForm"
                                label-width="80px"
                                size="mini"
                              >
                                <el-form-item
                                  label="车牌号码"
                                  :required="true"
                                  style="width: 280px; padding-top: 20px"
                                >
                                  <el-input
                                    v-model="carpayForm.carNum" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="车辆类型"
                                  :required="true"
                                  style="width: 280px"
                                >
                                  <el-input
                                    v-model="carpayForm.carTypeName" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="车辆品牌"
                                  :required="true"
                                  style="width: 280px"
                                >
                                  <el-input
                                    v-model="carpayForm.carBrand" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="车辆型号"
                                  :required="true"
                                  style="width: 280px"
                                >
                                  <el-input
                                    v-model="carpayForm.carModel" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="开始时间"
                                  :required="true"
                                  style="width: 280px"
                                >
                                  <el-input
                                    v-model="carpayForm.carpayIntime" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="结束时间"
                                  :required="true"
                                  style="width: 280px"
                                >
                                  <el-input
                                    v-model="carpayForm.carpayOuttime" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="缴费金额"
                                  :required="true"
                                  style="width: 260px"
                                >
                                  <el-input
                                    v-model="carpayForm.informationMoney" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                              </el-form>
                            </div>
                          </div>
                        </div>
                        <div class="right">
                          <div class="leftFont">车主基本信息：</div>
                          <div class="leftForm">
                            <div class="carpayForm">
                              <el-form
                                ref="carpayForm"
                                label-width="80px"
                                size="mini"
                              >
                                <el-form-item
                                  label="车主姓名"
                                  :required="true"
                                  style="
                                    width: 280px;
                                    padding-top: 20px;
                                    padding-left: 20px;
                                  "
                                >
                                  <el-input
                                    v-model="carpayForm.staffsName" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="联系方式"
                                  :required="true"
                                  style="width: 280px; padding-left: 20px"
                                >
                                  <el-input
                                    v-model="carpayForm.staffsTel" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="人员性别"
                                  :required="true"
                                  style="width: 280px; padding-left: 20px"
                                >
                                  <el-input
                                    v-model="carpayForm.staffsSex" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="单位名称"
                                  :required="true"
                                  style="width: 280px; padding-left: 20px"
                                >
                                  <el-input
                                    v-model="carpayForm.enterpriseName" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="所属楼宇"
                                  :required="true"
                                  style="width: 280px; padding-left: 20px"
                                >
                                  <el-input
                                    v-model="carpayForm.buildingName" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item
                                  label="房间名称"
                                  :required="true"
                                  style="width: 280px; padding-left: 20px"
                                >
                                  <el-input
                                    v-model="carpayForm.roomName" :disabled="true"
                                  ></el-input>
                                </el-form-item>
                                <el-form-item label="人脸照片" :required="true" style="width: 280px;padding-left: 20px">
                                  <div style="width: 100px;height: 100px;" class="demo-basic--circle">
                                    <div class="block">
                                      <el-avatar shape="square" :size="100" :src="carpayForm.staffsPhoto">
                                      </el-avatar>
                                    </div>
                                  </div>
                                </el-form-item>
                              </el-form>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div slot="footer" style="text-align: center">
                        <el-button @click="carpayMesg = false">取 消</el-button>
                      </div>
                    </el-dialog>
                    <el-popconfirm title="确定删除吗？" @confirm="delByid(scope.row.carpayId)">
                      <el-button slot="reference" type="text"  size="mini">删除</el-button>
                    </el-popconfirm>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </div>

          <div class="divPage">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryCarpay.currentPage"
              :page-sizes="[5, 10, 20, 50]"
              :page-size="queryCarpay.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="page.total"
            >
            </el-pagination>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      carpayList: [],
      carTypes: [],
      carpayAdd: false,
      carpayMesg: false,
      addCarpay: {},
      carpayForm: {},
      page: {
        total: 0, //总条数
      },
      queryCarpay: {
        currentPage: 1, //当前页
        pageSize: 5, //每页显示的条数
        carNum: "",
        staffsTel: "",
        carTypeName: "",
      },
    };
  },
  methods: {
    loadCarpays() {
      this.$axios.post("carpays", this.queryCarpay).then((res) => {
        this.carpayList = res.data.data.carpayList.list;
        this.carTypes = res.data.data.carTypes;
        this.page.total = res.data.data.carpayList.total;
      });
    },
    add() {
      this.$axios.post("carpays/add", this.carpayForm).then((res) => {
        if (res.data.code == 200) {
          this.$message.success("添加成功");
          this.carpayAdd = false;
          this.loadCarpays();
          // this.$refs.carpayForm.clearFiles();
        } else {
          this.$message.error("系统异常！请稍后重试");
        }
      });
    },
    // 详情按钮事件，根据车辆缴费id查找车辆相关信息
    handleClick(id) {
      this.$axios
        .post("carpays/sel/" + id)
        .then((res) => {
          this.carpayMesg = true;
          this.carpayForm = res.data.data.carpayVO;
          if(res.data.data.carpayVO.staffsSex == 1){
            this.carpayForm.staffsSex = "男";
          }else{
            this.carpayForm.staffsSex = "女";
          }
        })
        .catch((error) => {
          this.$message.error("系统异常！请稍后重试");
        });
    },
    //获得所有选中对象的id
    handleSelectionChange(val) {
      // console.log(val)
      this.listId = val;
    },
    //批量删除事件
    delByIds() {
      // 声明空数组,这里的数组是后端需要的数据
      const carpayIds = new Set();
      //遍历勾选数据取自己需要的id等这里是和后端需要的参数对应
      for (let i = 0; i < this.listId.length; i++) {
        carpayIds.add(this.listId[i].carpayId)//把取出的对象push到数组里
      }
      this.$axios.post("carpays/delByIds", carpayIds)
        .then(res => {
          if (res.data.code == 200) {
            this.$message.success("删除成功");
            this.loadCarpays();
          }
        })
        .catch((error) => {
          this.$message.error("系统异常！请稍后重试,请稍后重试");
        });
    },
    //根据id删除车辆缴费信息
    delByid(id) {
      this.$axios
        .delete("carpays/" + id)
        .then((res) => {
          if (res.data.code == 200) {
            this.$message.success("删除成功");
            this.loadCarpays();
          } else {
            this.$message.error("系统异常！请稍后重试");
          }
        })
    },
    //重置按钮
    allCarpays() {
      this.queryCarpay = {
        currentPage: 1, //当前页
        pageSize: 5, //每页显示的条数
        carNum: "",
        staffsTel: "",
        carTypeName: "",
      };
      this.loadCarpays();
    },
    //根据车牌号码查找车辆关联信息
    queryCarNum() {
      this.$axios
        .post("carpays/" + this.carpayForm.carNum)
        .then((res) => {
          this.carpayForm = res.data.data.carpayVO;
        })
        .catch((error) => {
          this.$message.error("该车辆未进出园区");
        });
    },
    //每一页显示的条数变化时，每页五条/每页十条
    handleSizeChange(val) {
      this.queryCarpay.pageSize = val;
      this.loadCarpays();
    },
    //当前页数变化时,上一页/下一页
    handleCurrentChange(val) {
      this.queryCarpay.currentPage = val;
      this.loadCarpays();
    },

    /**
     *关闭或取消模态框，清空asdsadad值
     */
    closeDialogAddgsVisible() {
      this.carpayForm = {
        //初始化from中的值
      };
    },
  },
  mounted() {
    this.loadCarpays();
  },
};
</script>
<style scoped>
.all {
  width: 100%;
  height: 700px;
  font-size: 30px;
  background-color: rgb(240, 242, 245);
}

.allContainer {
  width: 98%;
  margin: auto;
}

.head {
  background-color: white;
  width: 100%;
  height: 10px;
  line-height: 60px;
  margin: auto;
  border-radius: 10px;
  margin-top: 5px;
}

.divHead {
  background-color: cornflowerblue;
  width: 7px;
  height: 50%;
  float: left;
  margin-top: 15px;
  border-radius: 2px;
  margin-left: 8px;
}

.topFont {
  float: left;
  margin-left: 18px;
  font-size: 14px;
  font-weight: 900;
}

.divBtn {
  float: right;
  margin-right: 10px;
}

.bottomMain {
  border-radius: 8px;
  width: 100%;
  height: 620px;
  margin: auto;
  margin-top: 5px;
}

.divMain {
  width: 100%;
  height: 100%;
}

.mainTop {
  width: 100%;
  height: 13%;
  margin: auto;
  border: 1px solid darkgray;
  border-radius: 5px;
}

.divInputAll {
  background-color: white;
  width: 100%;
  height: 40px;
  line-height: 40px;
  margin: auto;
  border-radius: 10px;
  margin-top: 5px;
}

.divInput {
  border: 0px solid red;
  width: 23%;
  height: 100%;
  line-height: 60px;
  margin-left: 30px;
  float: left;
}

.divSelect {
  border: 0px solid red;
  width: 24.9%;
  height: 100%;
  line-height: 60px;
  margin-left: 30px;
  float: left;
}

.likeBtn {
  float: right;
  margin-right: 12px;
  line-height: 60px;
}

.inputFont {
  float: left;
  font-size: 2px;
}

.optionFont {
  float: right;
  color: #8492a6;
  font-size: xx-small;
}

.divSelAll {
  width: 100%;
  height: 75%;
  margin-top: 8px;
  line-height: 20px;
}

.divPage {
  width: 100%;
  height: 2%;
  margin-top: 20px;
  line-height: 10px;
}

.el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 54%;
  left: 57.5%;
  transform: translate(-50%, -50%);
  height: 700px;
  width: 1135px;
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}

.el-dialog .el-dialog__body {
  flex: 1;
  overflow: auto;
}

.dialogAll {
  border: 0px solid red;
  width: 98%;
  height: 105%;
  margin: auto;
  margin-top: -30px;
}

.left {
  border: 0px solid red;
  width: 48%;
  height: 100%;
  float: left;
}

.right {
  border: 0px solid red;
  width: 50%;
  height: 100%;
  float: right;
}

.leftFont,
.rightFont {
  border: 0px solid red;
  width: 90%;
  height: 5%;
  line-height: 20px;
  text-align: left;
  font-weight: 500;
  font-family: "微软楷体";
  margin-left: 10px;
}

.leftForm,
.rightForm {
  border: 2px dashed #8492a6;
  border-radius: 10px;
  width: 99%;
  height: 94%;
}

.visitorForm,
.carForm {
  border: 0px solid red;
  width: 90%;
  height: 95%;
  margin: auto;
  margin-top: 30px;
  margin-left: 35px;
}
</style>
